﻿@{
    ViewBag.Title = "QUnit Example";
    Layout = "~/Views/Shared/_Layout.Test.cshtml";
}

  @CoffeeScripts.Render("~/CoffeeScripts/shared/coffee");
 @CoffeeScripts.Render("~/CoffeeScripts/models/coffee");
<script type="text/coffeescript">
_file1path = "/CoffeeScripts/tests/data/json/1.txt";
_arch1path = "/CoffeeScripts/tests/data/json/3.txt";
_dir1path = "/CoffeeScripts/tests/data/json/2.txt";

asyncTest( "Parse file from JSON", () ->  
  $.getJSON(_file1path)
  .success((xhr, s, e) =>
        ok(xhr != null, "_file1path is null")        
        _file1 = Cofe.Entry.fromJson(xhr)
        console.log(_file1)
        ok(_file1 != null, "Constructor returns null")  
        ok(_file1.path == "{cofe}/testParse1.txt", "Path unmatched")
        ok(_file1.label == "testParse1.txt", "Label unmatched")
        ok(_file1.type == "file", "Type unmatched")
        ok(_file1.id == "1", "Id unmatched")
        ok(_file1.length == 0, "Size unmatched")
        ok(_file1.links.self.url == _file1path, "Url unmatched")                
        start()
      )
  .error((xhr, s, e) => 
        ok(false, "_file1path - " + e)
        start()
      )  
  )
asyncTest( "Parse archive from JSON", () ->  
  $.getJSON(_arch1path)
  .success((xhr, s, e) =>
        ok(xhr != null, "_arch1path is null")        
        _arch1 = Cofe.Entry.fromJson(xhr)
        console.log(_arch1)      
        ok(_arch1.path == "{cofe}/COFE3.zip", "Path unmatched")
        ok(_arch1.label == "COFE3.zip", "Label unmatched")
        ok(_arch1.type == "file", "Type unmatched")
        ok(_arch1.id == "3", "Id unmatched")
        ok(_arch1.length == 4641, "Size unmatched.")
        ok(_arch1.links.self.url == _arch1path, "Url unmatched")        
        ok(_arch1.links.list != undefined, "List not defined")  
        ok(_arch1.links.stream != undefined, "Stream not defined")  
        start()
      )
  .error((xhr, s, e) => 
        ok(false, "_arch1path - " + e)
        start()
      )  
  )
asyncTest( "Parse directory from JSON", () ->  
  $.getJSON(_dir1path)
  .success((xhr, s, e) =>
        ok(xhr != null, "_dir1path is null")        
        _dir1 = Cofe.Entry.fromJson(xhr)
        console.log(_dir1)
        ok(_dir1 != null, "Constructor returns null")  
        ok(_dir1.path == "{cofe}/DB", "Path unmatched")
        ok(_dir1.label == "DB", "Label unmatched")
        ok(_dir1.type == "directory", "Type unmatched")
        ok(_dir1.id == "2", "Id unmatched")
        ok(_dir1.length == undefined, "Size should be undefined.")
        ok(_dir1.links.self.url == _dir1path, "Url unmatched")        
        ok(_dir1.links.list != undefined, "List not defined")  
        start()
      )
  .error((xhr, s, e) => 
        ok(false, "_dir1path - " + e)
        start()
      )  
  )

asyncTest( "Load file from Cache", () ->  
  $.getJSON(_file1path)
  .success((xhr, s, e) =>
        ok(xhr != null, "_file1path is null")        
        _file1 = Cofe.Entry.fromJson(xhr)        
        _cachedFile1 = Cofe.Entry.fromId("1")
        console.log(_cachedFile1)
        ok(_cachedFile1 != undefined, "Not cached")
        ok(_file1.id == _cachedFile1.id, "Id unmatched")
        start()
      )
  .error((xhr, s, e) => 
        ok(false, "_file1path - " + e)
        start()
      )  
)

asyncTest( "Compare two items", () ->  
  $.getJSON(_file1path)
  .success((xhr, s, e) =>
        _file1 = Cofe.Entry.fromJson(xhr)         
        $.getJSON(_arch1path)
        .success((xhr, s, e) =>
          _archive1 = Cofe.Entry.fromJson(xhr)        
          console.log(_file1.compare(_archive1))
          ok(true)
          start()
        )
  )
  .error((xhr, s, e) => 
        ok(false, "_file1path - " + e)
        start()
      )      
)
</script>

